<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:include="common/common :: common_head('批量导入题库')"></head>
<head>
    <link rel="stylesheet" th:href="@{/css/back/test-manage.css}">

</head>
<body>
    <!-- 引入公共的导航部分 -->
    <header th:include="~{/common/common :: common_header_back('',批量导入题库)}"></header>

    <article>
        <!-- 侧边栏部分 -->
        <nav th:include="~{/common/common :: common_left_nav('','')}"></nav>
        <!-- 显示内容的部分 -->
        <div class="context-wrap">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-card">
                        <div class="layui-card-header">导入题库(题库格式仅支持.xls文件，请将题库至于桌面)</div>
                        <div class="layui-card-body ">
                            <form class="layui-form" action="">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">路径</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="path" required lay-verify="required" placeholder="请输入文件名" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="import">开始导入</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </article>
</body>
</html>
<script>
    layui.use(['element','form'], function(){
        let layer = layui.layer;
        let form = layui.form;
        let $ = layui.jquery;
        form.on('submit(import)', function(data){

            $.ajax({
                url: '/question/importQuestion',
                method: 'post',
                data: data.field,
                dataType: 'JSON',
                success: function (res){
                    if (res == 1){
                        //添加成功
                        layer.msg('导入成功！', {
                            time: 10000, //10s后自动关闭
                            btn: ['知道了']
                        });
                        $(".layui-form")[0].reset();
                        layui.form.render();
                    }else if(res==0){
                        //添加成功
                        layer.msg('系统找不到路径', {
                            time: 10000, //10s后自动关闭
                            btn: ['知道了']
                        });
                        $(".layui-form")[0].reset();
                        layui.form.render();
                    }else if(res==2){
                        //添加成功
                        layer.msg('无法解析此文件', {
                            time: 10000, //10s后自动关闭
                            btn: ['知道了']
                        });
                        $(".layui-form")[0].reset();
                        layui.form.render();
                    }
                }
            },JSON)
            return false;
        });

    });
</script>